package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.UserVocAISituationDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserVocAISituationCommand;
import com.cskaoyan.wordmemorize.service.AIReadService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/admin/voc/ai-read")
@RequiredArgsConstructor
public class AdminAIReadController {


    @Autowired
    AIReadService aiReadService;

    @PostMapping("/situation")
    public Result addSituation(@RequestBody UserVocAISituationCommand command) {
        aiReadService.addAISituation(command);
        return Result.ok();
    }

    @PutMapping("/situation")
    public Result updateSituation(@RequestBody UserVocAISituationCommand command) {
        aiReadService.updateAISituation(command);
        return Result.ok();
    }

    @DeleteMapping("/situation/{id}")
    public Result deleteSituation(@PathVariable Long id) {
        aiReadService.deleteAISituation(id);
        return Result.ok();
    }

    @DeleteMapping("/option/{id}")
    public Result deleteSituationOption(@PathVariable Long id) {
        aiReadService.deleteAISituationOption(id);
        return Result.ok();
    }

    @DeleteMapping("/situation")
    public Result batchDeleteSituationOption(@RequestBody BatchDeleteCommand command) {

        List<String> stringIds = command.getIds();
        List<Long> longIds = stringIds.stream()
                .map(Long::valueOf)
                .collect(Collectors.toList());
        aiReadService.batchDeleteAISituationOption(longIds);
        return Result.ok();
    }

    @GetMapping("/situation/list")
    public Result<PageDTO<UserVocAISituationDTO>> getSituationList(PageRequest pageRequest) {
        PageDTO<UserVocAISituationDTO> pageDTO = aiReadService.getAISituationList(pageRequest);
        return Result.ok(pageDTO);
    }
}
